package com.qf.sl.youshare;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import com.qf.sl.youshare.adapters.CommonFragmentAdapter;
import com.qf.sl.youshare.fragments.TutorialImageFragment;
import com.qf.sl.youshare.fragments.TutorialJumpFragment;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by IDEA
 * User : sl
 * on 2015/2/4.
 * 10:11
 */

/**
 * 教程页 Activity
 */
public class TutorialActivity extends FragmentActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tutorial);

        //保存已经显示过的信息,这样下次直接进入主页面
        SharedPreferences sp = getSharedPreferences(Constants.SP_APP_DATA, MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean(Constants.SP_KEY_TUTORIAL_SHOWN, true);
        editor.commit();

        //初始化ViewPager
        ViewPager pager = (ViewPager) findViewById(R.id.tutorial_pager);

        List<Fragment> fragments = new LinkedList<Fragment>();

        //TODO 添加 Fragment
        //添加教程的第一页
        TutorialImageFragment fragment = new TutorialImageFragment();
        Bundle args = new Bundle();

        args.putInt(
                Constants.ARG_TUTORIAL_IMAGE_LAYOUT_ID,
                R.layout.fragment_tutorial_image_1
            );

        fragment.setArguments(args);
        fragments.add(fragment);

        //添加教程的第二页
        fragment = new TutorialImageFragment();
        args = new Bundle();

        args.putInt(
                Constants.ARG_TUTORIAL_IMAGE_LAYOUT_ID,
                R.layout.fragment_tutorial_image_2
            );

        fragment.setArguments(args);
        fragments.add(fragment);

        //添加教程的第三页
        fragment = new TutorialImageFragment();
        args = new Bundle();

        args.putInt(
                Constants.ARG_TUTORIAL_IMAGE_LAYOUT_ID,
                R.layout.fragment_tutorial_image_3
            );

        fragment.setArguments(args);
        fragments.add(fragment);

        //添加第四页
        fragments.add(new TutorialJumpFragment());

        //设置通用的 Adapter
        CommonFragmentAdapter adapter = new CommonFragmentAdapter(
                getSupportFragmentManager(),
                fragments
            );

        pager.setAdapter(adapter);
    }
}